import gdata.youtube.service

class youtubeData(object):
    
    def initializeAPI(self):
        # Initialization
        self.yt_service = gdata.youtube.service.YouTubeService()
        
        # Turn on HTTPS/SSL access.
        # Note: SSL is not available at this time for uploads.
        self.yt_service.ssl = True
    
        self.yt_service.developer_key = 'AI39si4EP9rRCk1du5jbJuOukmisVdNWrf4wT3JqpRim_PV6z87AWuS-iFQwthxVb98K8pQdDFr8naJ-VZdtYEizF5Vyrf5Tfw'
        self.yt_service.client_id = 'MusicRecommender'
    
    def getTopVideo(self, searchTerm):
        #yt_service = gdata.youtube.service.YouTubeService()
        query = gdata.youtube.service.YouTubeVideoQuery()
        query.vq = searchTerm
        query.orderby = 'relevance'
        query.racy = 'include'
        feed = self.yt_service.YouTubeQuery(query)
        if (feed.entry):
            return feed.entry[0]
        else:
            return None
